//
//  226_翻转二叉树.swift
//  Swift-LeetCode
//
//  Created by 卢悦明 on 2024/2/6.
//

import UIKit
/**
 本质考点是二叉树的遍历，只要遍历每个节点，进行左右子树交换即可
 */
class FanZhuanBinaryTree: NSObject {
    @discardableResult func invertTree(_ root: TreeNode<Int>?) -> TreeNode<Int>? {
        guard let node = root else {
            return nil
        }
        (node.left, node.right) = (node.right, node.left)
        invertTree(node.left)
        invertTree(node.right)
        return node
    }
}
